package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.AdminDAO;
import com.pojo.Admin;
import com.util.PasswordUtil;
import org.springframework.stereotype.Service;

@Service("adminService")
public class AdminService extends ServiceImpl<AdminDAO, Admin> {

    /**
     * 管理员登录
     * @param username 用户名
     * @param password 密码
     * @return  管理员pojo对象
     */
    public Admin login(String username, String password) {
        QueryWrapper q = new QueryWrapper();
        q.eq("username",username);
        q.eq("password",password);
        Admin admin = super.getOne(q);
        return admin;
    }

    public String wyUpdatePassword(String oldPwd, String newPwd, String id) {
        Admin wuye = super.getById(id) ;
        if(!PasswordUtil.jiami(oldPwd).equals(wuye.getPassword())) {
            return "原始密码错误" ;
        }
        wuye.setPassword(PasswordUtil.jiami(newPwd));
        super.updateById(wuye) ;
        return null ;
    }


}
